package com.awa.usercenter.controller;

import com.awa.usercenter.common.BaseResponse;
import com.awa.usercenter.common.Code;
import com.awa.usercenter.common.utils.ResultUtils;
import com.awa.usercenter.exception.BusinessException;
import com.awa.usercenter.model.domain.AdminAuth;
import com.awa.usercenter.model.domain.CompanyAuth;
import com.awa.usercenter.service.AdminAuthService;
import com.awa.usercenter.service.CompanyAuthService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/auth")
@Tag(name = "管理员认证")
public class AdminAuthController {

    @Resource
    private AdminAuthService adminAuthService;
    @PostMapping("/table")
    @Parameter(name="pageNum",description = "当前页码",required = true)
    @Parameter(name="pageSize",description = "每页显示的数据条数",required = true)
    @Operation(summary = "管理员认证表单")
            private BaseResponse authmsg(@RequestParam("pageNum") Long pageNum, @RequestParam("pageSize") Long pageSize){
        Page<AdminAuth> page = adminAuthService.page(new Page<>(pageNum, pageSize));
        return ResultUtils.success(page);
    }
    @PostMapping("/accept")
    @Operation(summary = "管理员认证批量审批")
    @Parameter(name="datalist",description = "多个认证id",required = true)
    private BaseResponse accept(@RequestParam("datalist") List<String> datalist)
    {
        int accept = 1;
        List<AdminAuth> adminAuths = adminAuthService.switchStatus(accept, datalist);
        if(adminAuths!=null){
            if (adminAuthService.updateBatchById(adminAuths)) {
                return ResultUtils.success(null);
            }
            else throw new BusinessException(Code.SYSTEM_ERROR);
        }
        else throw new BusinessException(Code.SYSTEM_ERROR);
    }
    @PostMapping("/ignore")
    @Operation(summary = "管理员认证批量忽略")
    @Parameter(name="datalist",description = "多个认证id",required = true)
    private BaseResponse ignore(@RequestParam("datalist") List<String> datalist)
    {
        int ignore = 2;
        List<AdminAuth> adminAuths = adminAuthService.switchStatus(ignore, datalist);
        if(adminAuths!=null){
            if (adminAuthService.updateBatchById(adminAuths)) {
                return ResultUtils.success(null);
            }
            else throw new BusinessException(Code.SYSTEM_ERROR);
        }
        else throw new BusinessException(Code.SYSTEM_ERROR);
    }
    @PostMapping("/drawback")
    @Parameter(name="datalist",description = "多个认证id",required = true)
    @Operation(summary = "管理员认证批量撤回")
    private BaseResponse drawback(@RequestParam("datalist") List<String> datalist)
    {
        int drawback = 0;
        List<AdminAuth> adminAuths = adminAuthService.switchStatus(drawback, datalist);
        if(adminAuths!=null){
            if (adminAuthService.updateBatchById(adminAuths)) {
                return ResultUtils.success(null);
            }
            else throw new BusinessException(Code.SYSTEM_ERROR);
        }
        else throw new BusinessException(Code.SYSTEM_ERROR);
    }
}
